<?php

use yii\db\Migration;
use yii\db\Schema;

class m161226_092227_cruise extends Migration
{
    public function up(){//{{{

        $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB';
        // 游轮基础信息
        $this->createTable('cruise', [
            "id" =>         Schema::TYPE_PK,
            "supplier_id" =>Schema::TYPE_STRING.    "(5) NOT NULL COMMENT '所属供应商编号'",
            "name" =>       Schema::TYPE_STRING.    "(128) NULL COMMENT '名称'",
            "en_name" =>    Schema::TYPE_STRING.    "(255) NULL COMMENT '英文名称'",
            "from_city" =>  Schema::TYPE_INTEGER.   "(5) DEFAULT  '0' COMMENT '出发城市'",
            "weight" =>     Schema::TYPE_DECIMAL.   "(10,2) DEFAULT NULL COMMENT '重量  吨'",
            "num" =>        Schema::TYPE_INTEGER.   "(9) DEFAULT  '0' COMMENT '载客人数 人'",
            "length" =>     Schema::TYPE_INTEGER.   "(9) DEFAULT  '0' COMMENT '长度 米'",
            "width" =>      Schema::TYPE_INTEGER.   "(9) DEFAULT  '0' COMMENT '宽度 米'",
            "room" =>       Schema::TYPE_INTEGER.   "(9) DEFAULT  '0' COMMENT '客房数 间'",
            "ceil" =>       Schema::TYPE_INTEGER.   "(9) DEFAULT  '0' COMMENT '楼层数 层'",
            "speed" =>      Schema::TYPE_INTEGER.   "(6) DEFAULT  '0' COMMENT '船速 节'",
            "first" =>      Schema::TYPE_STRING.    "(32) NULL COMMENT '首航时间 2014 年'",
            "desc" =>       Schema::TYPE_STRING.    "(1024) NULL COMMENT '描述'",
            "status" =>     Schema::TYPE_INTEGER.   "(1) DEFAULT  '1' COMMENT '1正常  2禁用'",
            "user_id" =>    Schema::TYPE_INTEGER.   "(10) DEFAULT '0' COMMENT '管理员编号'",
            "created_at" => Schema::TYPE_DATETIME. " NULL",
            "updated_at" => Schema::TYPE_TIMESTAMP. " NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP",
        ], $tableOptions);


        // 舱房信息
        $this->createTable('room', [
            "id" =>         Schema::TYPE_PK,
            "cruise_id" =>  Schema::TYPE_STRING.    "(11) NOT NULL COMMENT '游轮编号'",
            "name" =>       Schema::TYPE_STRING.    "(128) NULL COMMENT '名称'",
            "code" =>       Schema::TYPE_STRING.    "(16) NULL COMMENT '简码'",
            "windows" =>    Schema::TYPE_INTEGER.   "(1) DEFAULT  '1' COMMENT '1 无窗 2 有窗'",
            "area" =>       Schema::TYPE_INTEGER.   "(8) DEFAULT  '0' COMMENT '面积  平米'",
            "num" =>        Schema::TYPE_STRING.    "(16) NULL  COMMENT '入住人数 '",
            "ceil" =>       Schema::TYPE_STRING.    "(64) NULL  COMMENT '所在楼层 JSON [1,2,4,5]'",
            "desc" =>       Schema::TYPE_STRING.    "(512) NULL COMMENT '描述'",
            "status" =>     Schema::TYPE_INTEGER.   "(1) DEFAULT  '1' COMMENT '1正常  2禁用'",
            "user_id" =>    Schema::TYPE_INTEGER.   "(10) DEFAULT '0' COMMENT '管理员编号'",
            "created_at" => Schema::TYPE_DATETIME. " NULL",
            "updated_at" => Schema::TYPE_TIMESTAMP. " NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP",
        ], $tableOptions);
        $this->createIndex("room_cruise", "room", "cruise_id");

        // 餐厅信息
        $this->createTable('restaurant', [
            "id" =>         Schema::TYPE_PK,
            "cruise_id" =>  Schema::TYPE_STRING.    "(11) NOT NULL COMMENT '游轮编号'",
            "name" =>       Schema::TYPE_STRING.    "(128) NULL COMMENT '名称'",
            "num" =>        Schema::TYPE_STRING.    "(16) NULL  COMMENT '容纳人数 '",
            "spend" =>      Schema::TYPE_STRING.    "(64) NULL  COMMENT '消费'",
            "ceil" =>       Schema::TYPE_STRING.    "(64) NULL  COMMENT '所在楼层 JSON [1,2,4,5]'",
            "desc" =>       Schema::TYPE_STRING.    "(512) NULL COMMENT '描述'",
            "status" =>     Schema::TYPE_INTEGER.   "(1) DEFAULT  '1' COMMENT '1正常  2禁用'",
            "user_id" =>    Schema::TYPE_INTEGER.   "(10) DEFAULT '0' COMMENT '管理员编号'",
            "created_at" => Schema::TYPE_DATETIME. " NULL",
            "updated_at" => Schema::TYPE_TIMESTAMP. " NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP",
        ], $tableOptions);
        $this->createIndex("restaurant_cruise", "restaurant", "cruise_id");

        // 娱乐设施信息
        $this->createTable('recreation', [
            "id" =>         Schema::TYPE_PK,
            "cruise_id" =>  Schema::TYPE_STRING.    "(11) NOT NULL COMMENT '游轮编号'",
            "name" =>       Schema::TYPE_STRING.    "(128) NULL COMMENT '名称'",
            "num" =>        Schema::TYPE_STRING.    "(16) NULL  COMMENT '容纳人数 '",
            "spend" =>      Schema::TYPE_STRING.    "(64) NULL  COMMENT '消费'",
            "ceil" =>       Schema::TYPE_STRING.    "(64) NULL  COMMENT '所在楼层 JSON [1,2,4,5]'",
            "desc" =>       Schema::TYPE_STRING.    "(512) NULL COMMENT '描述'",
            "status" =>     Schema::TYPE_INTEGER.   "(1) DEFAULT  '1' COMMENT '1正常  2禁用'",
            "user_id" =>    Schema::TYPE_INTEGER.   "(10) DEFAULT '0' COMMENT '管理员编号'",
            "created_at" => Schema::TYPE_DATETIME. " NULL",
            "updated_at" => Schema::TYPE_TIMESTAMP. " NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP",
        ], $tableOptions);
        $this->createIndex("recreation_cruise", "recreation", "cruise_id");

        // 服务信息
        $this->createTable('service', [
            "id" =>         Schema::TYPE_PK,
            "cruise_id" =>  Schema::TYPE_STRING.    "(11) NOT NULL COMMENT '游轮编号'",
            "name" =>       Schema::TYPE_STRING.    "(128) NULL COMMENT '名称'",
            "spend" =>      Schema::TYPE_STRING.    "(64) NULL  COMMENT '消费'",
            "ceil" =>       Schema::TYPE_STRING.    "(64) NULL  COMMENT '所在楼层 JSON [1,2,4,5]'",
            "desc" =>       Schema::TYPE_STRING.    "(512) NULL COMMENT '描述'",
            "status" =>     Schema::TYPE_INTEGER.   "(1) DEFAULT  '1' COMMENT '1正常  2禁用'",
            "user_id" =>    Schema::TYPE_INTEGER.   "(10) DEFAULT '0' COMMENT '管理员编号'",
            "created_at" => Schema::TYPE_DATETIME. " NULL",
            "updated_at" => Schema::TYPE_TIMESTAMP. " NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP",
        ], $tableOptions);
        $this->createIndex("service_cruise", "service", "cruise_id");


        // 图片信息
        $this->createTable('image', [
            "id" =>         Schema::TYPE_PK,
            "product_id" => Schema::TYPE_STRING.    "(11) NOT NULL COMMENT '外键编号(游轮 舱房 餐厅 娱乐 服务)'",
            "name" =>       Schema::TYPE_STRING.    "(128) NULL COMMENT '名称'",
            "type" =>       Schema::TYPE_INTEGER.   "(1) DEFAULT  '1' COMMENT '1游轮 2 舱房 3 餐厅  4 娱乐 5 服务 '",
            "cover" =>      Schema::TYPE_INTEGER.   "(1) DEFAULT  '0' COMMENT '1封面  0 普通'",
            "status" =>     Schema::TYPE_INTEGER.   "(1) DEFAULT  '1' COMMENT '1正常  2禁用'",
            "user_id" =>    Schema::TYPE_INTEGER.   "(10) DEFAULT '0' COMMENT '管理员编号'",
            "created_at" => Schema::TYPE_DATETIME. " NULL",
            "updated_at" => Schema::TYPE_TIMESTAMP. " NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP",
        ], $tableOptions);
        $this->createIndex("image_product", "image", "product_id");


    }//}}}

    public function down()
    {
        echo "m161226_092227_cruise cannot be reverted.\n";
        $this->dropTable('cruise');
        $this->dropTable('room');
        $this->dropTable('restaurant');
        $this->dropTable('recreation');
        $this->dropTable('service');
        $this->dropTable('image');
        return false;
    }

}
